package com.fh.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundValueOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author whf
 * @date 2023年04月23日 11:25
 */
@Component
public class RedisUtils {

    @Autowired
    private StringRedisTemplate redisTemplate;


    public boolean add(String id,String token){
        BoundValueOperations<String, String> str = redisTemplate.boundValueOps(id);
        Boolean aBoolean = str.setIfAbsent(token);
        str.expire(1000,TimeUnit.MINUTES);
        return aBoolean;
    }

    public String getToken(String id){
        BoundValueOperations<String, String> str = redisTemplate.boundValueOps(id);
        String s = str.get();
        return s;
    }

    public boolean del(String id){
        Boolean delete = redisTemplate.delete(id);
        return delete;
    }

}
